# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=pango
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.48.10
pkgrel=1
pkgdesc="A library for layout and rendering of text (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.pango.org/"
license=('LGPL2.1')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
            "${MINGW_PACKAGE_PREFIX}-meson"
            "${MINGW_PACKAGE_PREFIX}-ninja"
            "${MINGW_PACKAGE_PREFIX}-gi-docgen")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-libthai")
options=('staticlibs' 'strip' 'emptydirs')
source=("https://download.gnome.org/sources/pango/${pkgver:0:4}/${_realname}-${pkgver}.tar.xz"
        "0001-pango-shape.c-Use-the-former-rounding-code-as-needed.patch")
sha256sums=('21e1f5798bcdfda75eabc4280514b0896ab56f656d4e7e66030b9a2535ecdc98'
            '830ef46421ce0828dd9228087e5bcc1b64ab524a7f1507d120328c1c2dd91113')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-pango-shape.c-Use-the-former-rounding-code-as-needed.patch"
}

build() {
  cd "${srcdir}"
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --default-library shared \
    --buildtype plain \
    --auto-features=enabled \
    -Dgtk_doc=true \
    -Dxft=disabled \
    --wrap-mode=nofallback \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile

  cd "${srcdir}"
  [[ -d build-static-${MINGW_CHOST} ]] && rm -rf build-static-${MINGW_CHOST}
  mkdir -p build-static-${MINGW_CHOST}
  cd build-static-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --default-library static \
    --buildtype plain \
    --auto-features=enabled \
    -Dgtk_doc=false \
    -Dintrospection=disabled \
    --wrap-mode=nofallback \
    -Dxft=disabled \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" meson install
  
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" meson install

  # remove installed tests, no need and they contain the build path which
  # leads to pkgbuild warnings
  rm -Rf "${pkgdir}${MINGW_PREFIX}/share/installed-tests"
  rm -Rf "${pkgdir}${MINGW_PREFIX}/libexec"

  # License
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
